package com.app.controller;

import com.app.mapper.CategoryMapper;
import com.app.model.CategoryModel;
import com.app.service.GobiService;
import com.app.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * ⼽壁盛产
 */
@Controller
@RestController
@RequestMapping("/api")
public class GobiController {
    @Autowired
    private GobiService gobiService;
    @Autowired
    private CategoryMapper categoryMapper;

    //类型列表
    @GetMapping("/gobiTypeList")
    public Result<Object> gobiTypeList() {
        QueryWrapper<CategoryModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid", 5);
        return Result.success(categoryMapper.selectList(queryWrapper));
    }

    //列表
    @GetMapping("/getGobiList")
    public Result<Object> getVideoList(Integer page, Integer limit, String keyword, Integer type, HttpServletRequest request,Integer township) {
        Double longitude = null;
        Double latitude = null;
        if (request.getHeader("longitude") != null) {
            longitude = Double.parseDouble(request.getHeader("longitude"));
        }
        if (request.getHeader("latitude") != null) {
            latitude = Double.parseDouble(request.getHeader("latitude"));
        }
        return Result.success(gobiService.selectList(page, limit, keyword, type, longitude, latitude,township));
    }

    //查看详情
    @GetMapping("/getGobiInfo")
    public Result<Object> getVideoInfo(Integer id) {
        return Result.success(gobiService.selectById(id));
    }

}
